package com.zrf.control;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zrf.service.LeaveService;
import com.zrf.service.PersonService;



@RequestMapping("/person")
@Controller
public class PersonControl {
	@Autowired
	private PersonService ps;
	@Autowired
	private LeaveService ls;
	

	@RequestMapping(value="first", params={"type","name"})
	public String first(@RequestParam("type") int type,
						@RequestParam("name") String name,
						 Map<String, Object> map){
		try {
			switch (type) {
			case 0:
				map.put("muqj", ls.findMyLeave(name));
				map.put("name", name);
			case 1:
				map.put("sp", ls.findOtherLeave(name, 0));
				map.put("fsp", ls.NofindOtherLeave(name, 0));
				map.put("name", name);
			}
			map.put("type", type);
			return "leave";
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "fail";
	}
	
	@RequestMapping(value="login", params={"type","name","pwd"})
	public String login(@RequestParam("type") int type,
						@RequestParam("name") String name,
						@RequestParam("pwd") String pwd){
		try {
			if (ps.login(name, pwd)) {
				return "redirect:/user/first?name="+name;
			}else {
				return "index";
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "fail";
	}

}
